package com.candy.control;

import com.alibaba.fastjson2.JSON;
import com.candy.service.UserInfoService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.LinkedList;

@WebServlet("/getUserInfoes")
public class GetUserInfoesServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        调用业务逻辑处理层，获取用户表中的所有数据
        UserInfoService userInfoService = new UserInfoService();
        LinkedList<LinkedHashMap<String,Object>> userinfoes= userInfoService.getUserInfoes();
// 对数据进行处理，转换为JSON字符串
        String userStr=JSON.toJSONString(userinfoes);
//        将处理好的数据响应给前端
        resp.getWriter().println(userStr);
    }
}
